package com.woniuxy.factory;

import com.woniuxy.entity.Person;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class BeanFactory2 {

    private static Map<String, Person> map = new HashMap<>();
    static {
        Properties properties = new Properties();
        Person person = null;

        try{
            InputStream resourceAsStream = BeanFactory.class.getClassLoader().getResourceAsStream("applicationContexts.properties");
            properties.load(resourceAsStream);
            Set<Object> keys = properties.keySet();
            for (Object key:keys) {
                person = (Person) Class.forName(properties.getProperty(key+"")).newInstance();
                map.put(key + "",person);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public Person getBean(String per){
        return map.get(per);
    }
}
